﻿using System;
using System.Linq.Expressions;
using NHibernate.Expression.Extensions.Utils;

namespace NHibernate.Expression.Extensions {
	public static class ICriteriaExtensions {
		public static ICriteria SetFetchMode<T>(this ICriteria criteria, Expression<Func<T, object>> property,
		                                        FetchMode mode) {
			return criteria.SetFetchMode(property.MemberName(), mode);
		}

		public static ICriteria SetFetchMode<T>(this ICriteria criteria, string prefix, Expression<Func<T, object>> property,
		                                        FetchMode mode) {
			return criteria.SetFetchMode(string.Format("{0}.{1}", prefix, property.MemberName()), mode);
		}
	}
}